package com.kasax.httpsupport;

import java.util.concurrent.TimeUnit;

public class CatHttpClient {
    private final Config config;

    public CatHttpClient(Builder builder) {
        this.config = new Config(builder);
    }

    public Call newCall(Request request) {
        return new HttpCall(config, request);
    }

    class Config {
        int connectTimeout;
        int readTimeout;
        int writeTimeout;

        public Config(Builder builder) {
            this.connectTimeout = builder.connectTimeout;
            this.readTimeout = builder.readTimeout;
            this.writeTimeout = builder.writeTimeout;
        }
    }


    public static class Builder {
        private int connectTimeout;
        private int readTimeout;
        private int writeTimeout;

        public Builder connectTimeout(int timeout, TimeUnit unit) {
            this.connectTimeout = (int) unit.toMillis(timeout);
            return this;
        }

        public Builder readTimeout(int timeout, TimeUnit unit) {
            this.readTimeout = (int) unit.toMillis(timeout);
            return this;
        }

        public Builder writeTimeout(int timeout, TimeUnit unit) {
            this.writeTimeout = (int) unit.toMillis(timeout);
            return this;
        }

        public CatHttpClient build() {
            return new CatHttpClient(this);
        }
    }
}
